package com.lsq.baseadmin.modules.manage.controller;

import com.github.pagehelper.PageInfo;
import com.lsq.baseadmin.modules.manage.entity.User;
import com.lsq.baseadmin.modules.manage.service.UserService;
import com.lsq.baseadmin.modules.manage.vo.UserVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 * 系统用户 前端控制器
 * </p>
 *
 * @author lsq
 * @since 2020-10-22
 */
@Api("用户")
@RestController
@RequestMapping("/user")
public class UserController {

    private UserService userService;

    public UserController(UserService userService) {
        this.userService = userService;
    }

    @ApiOperation("用户列表")
    @GetMapping("/list")
    public ResponseEntity list(User user, PageInfo page) {
        PageInfo pg = userService.pg(user, page.getPageNum(), page.getPageSize());
        return ResponseEntity.ok(pg);
    }

    @ApiOperation("用户详情")
    @GetMapping("/detail")
    public ResponseEntity detail(@RequestParam("id") int id) {
        UserVo userVo = userService.detail(id);
        return ResponseEntity.ok(userVo);
    }

    @ApiOperation("用户添加")
    @PostMapping("/add")
    public ResponseEntity add(@RequestBody UserVo userVo) {
        userService.add(userVo);
        return new ResponseEntity(HttpStatus.OK);
    }

    @ApiOperation("用户修改")
    @PostMapping("/update")
    public ResponseEntity update(@RequestBody UserVo userVo) {
        userService.update(userVo);
        return new ResponseEntity(HttpStatus.OK);
    }

    @ApiOperation("用户删除")
    @PostMapping("/delete")
    public ResponseEntity delete(int id) {
        userService.removeById(id);
        return new ResponseEntity(HttpStatus.OK);
    }

}
